package main;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import dao.FileIO;
import evaluation.EvaluationTool;

public class NDCREvaluator {

	public void proceed(String[] args) {

		String labelFile = args[0];
		String resultFile = args[1];
		int hours = Integer.parseInt(args[2]);
		String outputFile = args[3];

		List<Integer> labels = loadList(labelFile, false);
		List<Integer> predictList = loadList(resultFile, true);
		
		if(labels.size() != predictList.size()) {
			throw new RuntimeException();
		}
		
		double ndrc = EvaluationTool.getNDCR(labels, predictList, hours);
		
		FileIO.writeFile(outputFile, Arrays.asList(ndrc + "\n"));
	}
	
	protected List<Integer> loadList(String filename, boolean firstline) {
		List<String> lines = FileIO.readFile(filename);
		List<Integer> integers;
		
		Iterator<String> itr = lines.iterator();
		if(firstline) {
			integers = new ArrayList<Integer>(lines.size() - 1);
			itr.next();
		} else {
			integers = new ArrayList<Integer>(lines.size());
		}
		
		while(itr.hasNext()) {
			String line = itr.next().trim();
			integers.add(Integer.parseInt(line.trim().split("\\s")[0]));
		}
		
		return integers;
	}
	
	public static void main(String[] args) {
		NDCREvaluator m = new NDCREvaluator();
		m.proceed(args);
	}
}
